package com.smart.controller;

import com.smart.common.PageInfo;
import com.smart.common.WebResponse;
import com.smart.common.annotation.WebAccess;
import com.smart.model.request.ProjectItemUpdateRequest;
import com.smart.model.request.ProjectWeeklyItemAddRequest;
import com.smart.model.request.ProjectWeeklyItemPageRequest;
import com.smart.model.request.ProjectWeeklyTaskRequest;
import com.smart.model.request.WeeklyReportDetailRequst;
import com.smart.model.vo.ProjectItemVO;
import com.smart.model.vo.ProjectReportVO;
import com.smart.model.vo.ProjectVO;
import com.smart.model.vo.ProjectWeeklyItemVO;
import com.smart.model.vo.ProjectWeeklyTaskVO;
import com.smart.service.ProjectService;
import com.smart.service.ProjectWeeklyTaskService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author zhanghong
 */
@RestController
@RequestMapping("/weeklyTask")
@Api(value = "项目周报模块", tags = {"项目周报模块"})
public class ProjectWeeklyTaskController {

    @Autowired
    private ProjectWeeklyTaskService projectWeeklyTaskService;
    @Autowired
    private ProjectService projectService;

    @WebAccess(login = true)
    @ApiOperation(value = "【监管端|管理端】查看", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/getReportDetail")
    public WebResponse<ProjectReportVO> getReportDetail(@RequestBody WeeklyReportDetailRequst request) {
        return WebResponse.build(projectWeeklyTaskService.getReportDetail(request));
    }

    @WebAccess(login = true)
    @ApiOperation("【监管端|管理端】当前周提报的项目分页列表")
    @PostMapping("/pageQuery")
    public WebResponse<PageInfo<ProjectVO>> pageQuery(@RequestBody ProjectWeeklyTaskRequest request) {
        return WebResponse.build(projectWeeklyTaskService.pageQuery(request));
    }

    @WebAccess(login = true)
    @ApiOperation("【监管端|管理端】查询项目详情")
    @ApiImplicitParam(name = "projectId", value = "项目id")
    @PostMapping("/queryProjectDetail/{projectId}")
    public WebResponse<ProjectVO> queryProjectDetail(@PathVariable("projectId") Long projectId) {
        return WebResponse.build(projectService.getByKey(projectId));
    }

    @WebAccess(login = true)
    @ApiOperation("【监管端|管理端】未上传周报项目名单")
    @PostMapping("/unReportPageQuery")
    public WebResponse<PageInfo<ProjectVO>> unReportPageQuery(@RequestBody ProjectWeeklyTaskRequest request) {
        return WebResponse.build(projectWeeklyTaskService.unReportPageQuery(request));
    }

    @WebAccess(login = true)
    @ApiOperation("【监管端】周报信息项-添加")
    @PostMapping("/addItem")
    public WebResponse<Boolean> addItem(@RequestBody ProjectWeeklyItemAddRequest request) {
        return WebResponse.build(projectWeeklyTaskService.addItem(request));
    }

    @WebAccess(login = true)
    @ApiOperation("【监管端】周报信息项-编辑")
    @PostMapping("/updateItem")
    public WebResponse<Boolean> updateByKey(@RequestBody ProjectItemUpdateRequest request) {
        return WebResponse.build(projectWeeklyTaskService.updateItem(request));
    }
    @WebAccess(login = true)
    @ApiOperation("【监管端】周报信息项-分页查询")
    @PostMapping("/listItem")
    public WebResponse<PageInfo<ProjectWeeklyItemVO>> listItem(@RequestBody ProjectWeeklyItemPageRequest request) {
        return WebResponse.build(projectWeeklyTaskService.pageListItem(request));
    }

    @WebAccess(login = true)
    @ApiOperation("【监管端】周报下载文件类型")
    @PostMapping("/weeklyReportFileType")
    public WebResponse<String> weeklyReportFileType(@RequestBody ProjectWeeklyItemPageRequest request) {
        return WebResponse.build(projectWeeklyTaskService.weeklyReportFileType(request));
    }
}
